package com.rightrule.rule.executor.node;

import com.rightrule.rule.compile.Executable;
import com.rightrule.rule.executor.RuleFlow;
import com.rightrule.rule.executor.RuntimeContext;
import com.rightrule.rule.response.BaseExecutionResponse;
import com.rightrule.rule.response.NodeExecutionResponse;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.Map;


/**
 * 子规则流节点
 */
@Data
@Slf4j
@ToString
public class SubRuleFlowNode extends BaseNode implements Executable {

    /**
     * 规则内容
     */
    private RuleFlow ruleFlow;


    @Override
    public NodeExecutionResponse execute(RuntimeContext context, Map<String, Object> variableMap) {
        BaseExecutionResponse flowExecutionResponse = ruleFlow.execute(context, variableMap);

        NodeExecutionResponse nodeExecutionResponse = new NodeExecutionResponse();
        BeanUtils.copyProperties(flowExecutionResponse, nodeExecutionResponse);
        return nodeExecutionResponse;
    }
}
